home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 18 / AMIGAplus Sonderheft 18 (1999)(ICP)(DE)[!].iso / PD / Anwendungen / FS1541-13 / support.c < prev    next >
C/C++ Source or Header  |  1999-01-03  |  3KB  |  133 lines

  1.  
  2. /*
  3.  * FS1541 - support routines
  4.  *
  5.  * Copyright (C) 1996 - 1998 Michael Krause
  6.  *
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 2 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20.  */
  21.  
  22. #include <string.h>
  23.  
  24. #include <exec/types.h>
  25. #include <exec/execbase.h>
  26. #include <dos/dosextens.h>
  27. #include <dos/filehandler.h>
  28. #include <devices/input.h>
  29. #include <devices/inputevent.h>
  30.  
  31. #include <proto/exec.h>
  32.  
  33. #include "support.h"
  34. #include "main.h"
  35.  
  36. /*-------------------------------------------------------------------------*/
  37.  
  38. void ReturnPacket(struct DosPacket *packet, LONG res1, LONG res2)
  39. {
  40.     struct MsgPort *mp = packet->dp_Port;
  41.  
  42.     packet->dp_Port = ourport;
  43.     packet->dp_Res1 = res1;
  44.     packet->dp_Res2 = res2;
  45.  
  46.     PutMsg(mp, packet->dp_Link);
  47. }
  48.  
  49. struct DosPacket *GetPacket(struct MsgPort *port)
  50. {
  51.     struct Message *msg;
  52.  
  53.     if((msg = GetMsg(port)))
  54.         return((struct DosPacket *)msg->mn_Node.ln_Name);
  55.     else
  56.         return(NULL);
  57. }
  58.  
  59. /*-------------------------------------------------------------------------*/
  60.  
  61. void copy64name(STRPTR dest, STRPTR src, UBYTE maxlen)
  62. {
  63.     static const UBYTE conv[91]=
  64.         " !\"#$%&'()·+,-.\\0123456789|;<=>?"
  65.         "@abcdefghijklmnopqrstuvwxyz[£]^{"
  66.         "_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  67.     UBYTE a;
  68.  
  69.     while(((a=*src++) != 0xa0) && maxlen--)
  70.         if(a<32 || a>122)
  71.             *dest++ = '_';
  72.         else
  73.             *dest++ = conv[a-32];
  74.  
  75.     *dest = '\0';
  76. }
  77.  
  78. void asciito64(STRPTR dest, STRPTR src, UBYTE maxlen)
  79. {
  80.     static const UBYTE conv[91]=
  81.         " !\"#$%&'()*+,-./0123456789:;<=>?"
  82.         "@abcdefghijklmnopqrstuvwxyz[/]^{"
  83.         "-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  84.     UBYTE a;
  85.  
  86.     while((a=*src++) && maxlen--)
  87.         if(a<32 || a>122)
  88.             *dest++ = ' ';
  89.         else
  90.             *dest++ = conv[a-32];
  91.  
  92.     while(maxlen--)
  93.         *dest++ = 0xa0;
  94. }
  95.  
  96. /*-------------------------------------------------------------------------*/
  97.  
  98. void SendEvent(BOOL insert)
  99. {
  100.     struct IOStdReq *InputRequest;
  101.     struct MsgPort *InputPort;
  102.     struct InputEvent *ie;
  103.  
  104.     if((InputPort = (struct MsgPort*)CreateMsgPort()))
  105.     {
  106.         if((InputRequest = (struct IOStdReq*)CreateIORequest(InputPort, sizeof(struct IOStdReq))))
  107.         {
  108.             if(!OpenDevice("input.device", 0, (struct IORequest*)InputRequest, 0))
  109.             {
  110.                 if((ie = AllocVec(sizeof(struct InputEvent), MEMF_PUBLIC|MEMF_CLEAR)))
  111.                 {
  112.                     ie->ie_Class = insert ? IECLASS_DISKINSERTED : IECLASS_DISKREMOVED;
  113.                     InputRequest->io_Command = IND_WRITEEVENT;
  114.                     InputRequest->io_Data = ie;
  115.                     InputRequest->io_Length = sizeof(struct InputEvent);
  116.                     DoIO((struct IORequest*)InputRequest);
  117.                     FreeVec(ie);
  118.                 }
  119.                 CloseDevice((struct IORequest*)InputRequest);
  120.             }
  121.             DeleteIORequest (InputRequest);
  122.         }
  123.         DeleteMsgPort (InputPort);
  124.     }
  125. }
  126.  
  127. /*
  128.   Local Variables:
  129.   mode:c
  130.   c-basic-offset:8
  131.   End:
  132. */
  133.